import { defineStore } from 'pinia'
import type { UserInfo } from '@/types'

interface UserState {
  userInfo: UserInfo | null
  token: string
}

export const useUserStore = defineStore({
  id: 'user',
  
  state: (): UserState => ({
    userInfo: null,
    token: ''
  }),
  
  actions: {
    setToken(token: string) {
      this.token = token
    },
    
    setUserInfo(userInfo: UserInfo) {
      this.userInfo = userInfo
    },
    
    logout() {
      this.token = ''
      this.userInfo = null
    }
  },
  
  persist: {
    key: 'user',
    storage: localStorage,
    paths: ['token', 'userInfo']
  }
}) 